package com.dfch.auto.appium.app;

import java.lang.reflect.Field;

/**
 * @author ldcmaxim on 05/04/2018.
 */
public class AutoAppFactory {
    private static final Class<?>[] APP_CLASS_LIST = {AutoAndroidDouYin.class, AutoiOSDouYin.class};

    public static AutoApp getAutoApp(String platform, String tag) {
        AutoApp app = null;
        for (Class<?> clazz : APP_CLASS_LIST) {
            try {
                Field platformField = clazz.getDeclaredField("_platform");
                String strPlatform = platformField != null ? (String) platformField.get(null) : "";
                Field tagField = clazz.getDeclaredField("_tag");
                String strTag = tagField != null ? (String) tagField.get(null) : "";
                if (platform.equalsIgnoreCase(strPlatform) && tag.equalsIgnoreCase(strTag)) {
                    app = (AutoApp) clazz.newInstance();
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return app;
    }
}
